class CampaignsController < ApplicationController
  def index
    #@campaigns = current_user.campaigns
    sql = <<-SQL
      campaigns.*,sum(campaign_rpts.view_num) as view_num,sum(campaign_rpts.click_num) as click_num,sum(campaign_rpts.cost) as cost ,min(campaign_rpts.created_at) as min_created_at ,max(campaign_rpts.created_at) as max_created_at
    SQL
    @campaigns = Campaign.where(user_id: current_user.id).left_joins(:campaign_rpts).group(:id).select("#{sql}").paginate(page: params[:page]).order(created_at: :desc)
  end

  def new

  end
end
